package com.csl.testjetpack.ui

import android.os.Bundle
import android.util.Log
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.lifecycle.lifecycleScope
import com.csl.testjetpack.R
import com.csl.testjetpack.data.bean.RemoteButtonInfo
import com.csl.testjetpack.data.bean.RemoteInfo
import com.csl.testjetpack.data.db.RemoteDatabase
import com.csl.testjetpack.databinding.*
import com.csl.testjetpack.vm.RemoteListViewModel
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

/**
 * A simple [Fragment] subclass.
 * Use the [TestFragment.newInstance] factory method to
 * create an instance of this fragment.
 */
class RemoteListFragment : Fragment() {

    var binding: FragmentRemotelistBinding? = null
    var viewModel: RemoteListViewModel? = null
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

    }

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        // Inflate the layout for this fragment
        binding = FragmentRemotelistBinding.inflate(inflater)


        return binding!!.root
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        viewModel = RemoteListViewModel(requireActivity().application)

        lifecycleScope.launch {
            viewModel?.getData()

        }
    }



    override fun onDestroy() {
        super.onDestroy()
        binding = null
    }


}